//
// Created by 12992 on 24-10-26.
//

#ifndef RSA_H
#define RSA_H

#include "crypto.h"
#include <filesystem>
#include <openssl/evp.h>

namespace crypto
{
    class rsa final
        : public crypto
    {
    public:
        static void generate_key_pair(const std::filesystem::path& private_key,
                                      const std::filesystem::path& public_key);

        enum class key_type
        {
            PUBLIC,
            PRIVATE
        };

    public:
        explicit rsa(key_type type, const std::filesystem::path& key);

        ~rsa() override;

        rsa(const rsa&) = delete;

        rsa& operator=(const rsa&) = delete;

        rsa(rsa&&) noexcept;

        rsa& operator=(rsa&&) noexcept;

        std::string encrypt(const std::string&) override;

        std::string decrypt(const std::string&) override;

    private:
        EVP_PKEY* key{};
        EVP_PKEY_CTX* ctx{};
    };
}

#endif //RSA_H
